package com.mastercard.assets.web.struts.forms;

import javax.servlet.http.HttpServletRequest;


import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

import com.mastercard.assets.jpa.TblAsset;
import com.mastercard.assets.util.MCUtil;
import com.mastercard.assets.util.dao.MasterCardDAO;
import com.mastercard.assets.web.util.to.ManejadorPaquetesDeAsset;

public class AssetModificarPaquetesForm
	extends
		ActionForm
{
	private int operation ;
	private int cveAsset ;
	private ManejadorPaquetesDeAsset packageManager = new ManejadorPaquetesDeAsset( ) ;
	private String cantidad = "" ;
	private int cantidadI ;
	private int tipoHabitacion = 1 ;
	private int facturadoA = 1 ;
	private int fondeadoA = 1 ;
	
	private String eliminarSLL ;
	private String eliminarDLL ;
	private String eliminarSLR ;
	private String eliminarDLR ;
	private String eliminarSRL ;
	private String eliminarDRL ;
	private String eliminarSRR ;
	private String eliminarDRR ;
	
	private int eliminarSLLI ;
	private int eliminarDLLI ;
	private int eliminarSLRI ;
	private int eliminarDLRI ;
	private int eliminarSRLI ;
	private int eliminarDRLI ;
	private int eliminarSRRI ;
	private int eliminarDRRI ;

	// numero del 1 al 8 para indicar a cual tipo paquete se le va a quitar paquetes. 
	private int eliminar ;
	
	

	public String getEliminarSLL() {
		return eliminarSLL;
	}



	public void setEliminarSLL(String eliminarSLL) {
		this.eliminarSLL = eliminarSLL;
	}



	public String getEliminarDLL() {
		return eliminarDLL;
	}



	public void setEliminarDLL(String eliminarDLL) {
		this.eliminarDLL = eliminarDLL;
	}



	public String getEliminarSLR() {
		return eliminarSLR;
	}



	public void setEliminarSLR(String eliminarSLR) {
		this.eliminarSLR = eliminarSLR;
	}



	public String getEliminarDLR() {
		return eliminarDLR;
	}



	public void setEliminarDLR(String eliminarDLR) {
		this.eliminarDLR = eliminarDLR;
	}



	public String getEliminarSRL() {
		return eliminarSRL;
	}



	public void setEliminarSRL(String eliminarSRL) {
		this.eliminarSRL = eliminarSRL;
	}



	public String getEliminarDRL() {
		return eliminarDRL;
	}



	public void setEliminarDRL(String eliminarDRL) {
		this.eliminarDRL = eliminarDRL;
	}



	public String getEliminarSRR() {
		return eliminarSRR;
	}



	public void setEliminarSRR(String eliminarSRR) {
		this.eliminarSRR = eliminarSRR;
	}



	public String getEliminarDRR() {
		return eliminarDRR;
	}



	public void setEliminarDRR(String eliminarDRR) {
		this.eliminarDRR = eliminarDRR;
	}



	public int getEliminar() {
		return eliminar;
	}



	public void setEliminar(int eliminar) {
		this.eliminar = eliminar;
	}



	public int getEliminarSLLI() {
		return eliminarSLLI;
	}



	public int getEliminarDLLI() {
		return eliminarDLLI;
	}



	public int getEliminarSLRI() {
		return eliminarSLRI;
	}



	public int getEliminarDLRI() {
		return eliminarDLRI;
	}



	public int getEliminarSRLI() {
		return eliminarSRLI;
	}



	public int getEliminarDRLI() {
		return eliminarDRLI;
	}



	public int getEliminarSRRI() {
		return eliminarSRRI;
	}



	public int getEliminarDRRI() {
		return eliminarDRRI;
	}



	public int getOperation() {
		return operation;
	}



	public void setOperation(int operation) {
		this.operation = operation;
	}



	public String getCantidad() {
		return cantidad;
	}



	public void setCantidad(String cantidad) {
		this.cantidad = cantidad;
	}



	public int getCantidadI() {
		return cantidadI;
	}



	public void setCantidadI(int cantidadI) {
		this.cantidadI = cantidadI;
	}



	public int getTipoHabitacion() {
		return tipoHabitacion;
	}



	public void setTipoHabitacion(int tipoHabitacion) {
		this.tipoHabitacion = tipoHabitacion;
	}



	public int getFacturadoA() {
		return facturadoA;
	}



	public void setFacturadoA(int facturadoA) {
		this.facturadoA = facturadoA;
	}



	public int getFondeadoA() {
		return fondeadoA;
	}



	public void setFondeadoA(int fondeadoA) {
		this.fondeadoA = fondeadoA;
	}



	public ManejadorPaquetesDeAsset getPackageManager() {
		return packageManager;
	}



	public void setPackageManager(ManejadorPaquetesDeAsset packageManager) {
		this.packageManager = packageManager;
	}



	public int getCveAsset() {
		return cveAsset;
	}



	public void setCveAsset(int cveAsset) {
		this.cveAsset = cveAsset;
	}



	public ActionErrors validate( ActionMapping mapping , HttpServletRequest request )
	{
//		System.out.println( "Entra al validate" ) ;
//		
		ActionErrors errors = new ActionErrors( ) ;
		
		// si no hay cve
		if( cveAsset < 1 )
			errors.add( "CveEmpty" , new ActionMessage( "com.mastercard.assets.web.errors.modules.login.CveEmpty" ) ) ;
		
		if( operation == 1 )
		{
			if( cantidad == null || cantidad.trim( ).length( ) == 0 )
				errors.add( "CantidadEmpty" , new ActionMessage( "com.mastercard.assets.web.errors.modules.asset.packages.CantidadEmpty" ) ) ;
			
			try
			{
				cantidadI = Integer.parseInt( cantidad ) ;
			}catch( Exception e )
			{
				errors.add( "CantidadNotNumber" , new ActionMessage( "com.mastercard.assets.web.errors.modules.asset.packages.CantidadNotNumber" ) ) ;
			}
		}
		
		if( operation == 6 )
		{
			// verifica el tipo de paquete a eliminar
			switch( eliminar )
			{
				case 1 :
					
					try
					{
						eliminarSLLI = Integer.parseInt( eliminarSLL ) ;
					}catch( Exception e )
					{
						errors.add( "SLLDropNotNumber" , new ActionMessage( "com.mastercard.assets.web.errors.modules.asset.packages.SLLDropNotNumber" ) ) ;
					}
					
					break ;
				case 2 :
					
					try
					{
						eliminarSLRI = Integer.parseInt( eliminarSLR ) ;
					}catch( Exception e )
					{
						errors.add( "SLRDropNotNumber" , new ActionMessage( "com.mastercard.assets.web.errors.modules.asset.packages.SLRDropNotNumber" ) ) ;
					}
					
					break ;
				case 3 :
					
					try
					{
						eliminarSRLI = Integer.parseInt( eliminarSRL ) ;
					}catch( Exception e )
					{
						errors.add( "SRLDropNotNumber" , new ActionMessage( "com.mastercard.assets.web.errors.modules.asset.packages.SRLDropNotNumber" ) ) ;
					}
					
					break ;
				case 4 :
					
					try
					{
						eliminarSRRI = Integer.parseInt( eliminarSRR ) ;
					}catch( Exception e )
					{
						errors.add( "SRRDropNotNumber" , new ActionMessage( "com.mastercard.assets.web.errors.modules.asset.packages.SRRDropNotNumber" ) ) ;
					}
					
					break ;
				case 5 :
					
					try
					{
						eliminarDLLI = Integer.parseInt( eliminarDLL ) ;
					}catch( Exception e )
					{
						errors.add( "DLLDropNotNumber" , new ActionMessage( "com.mastercard.assets.web.errors.modules.asset.packages.DLLDropNotNumber" ) ) ;
					}
					
					break ;
				case 6 :
					
					try
					{
						eliminarDLRI = Integer.parseInt( eliminarSLR ) ;
					}catch( Exception e )
					{
						errors.add( "SLRDropNotNumber" , new ActionMessage( "com.mastercard.assets.web.errors.modules.asset.packages.SLRDropNotNumber" ) ) ;
					}
					
					break ;
				case 7 :
					
					try
					{
						eliminarDRLI = Integer.parseInt( eliminarDRL ) ;
					}catch( Exception e )
					{
						errors.add( "DRLDropNotNumber" , new ActionMessage( "com.mastercard.assets.web.errors.modules.asset.packages.DRLDropNotNumber" ) ) ;
					}
					
					break ;
				case 8 :
					
					try
					{
						eliminarDRRI = Integer.parseInt( eliminarDRR ) ;
					}catch( Exception e )
					{
						errors.add( "DRRDropNotNumber" , new ActionMessage( "com.mastercard.assets.web.errors.modules.asset.packages.DRRDropNotNumber" ) ) ;
					}
					
					break ;
                                case 9 :
					
					try
					{
						eliminarSRRI = Integer.parseInt( eliminarSRR ) ;
					}catch( Exception e )
					{
						errors.add( "SRRDropNotNumber" , new ActionMessage( "com.mastercard.assets.web.errors.modules.asset.packages.SRRDropNotNumber" ) ) ;
					}
					
					break ;
                                case 10 :
					
					try
					{
						eliminarDRRI = Integer.parseInt( eliminarDRR ) ;
					}catch( Exception e )
					{
						errors.add( "DRRDropNotNumber" , new ActionMessage( "com.mastercard.assets.web.errors.modules.asset.packages.DRRDropNotNumber" ) ) ;
					}
					
					break ;
				default :
					
					break ;
			}
		}
		
		if( errors.size( ) > 0 )
		{
			System.out.println( "AssetModificarPaqueteForm.java: cveAsset/" + cveAsset ) ;
			
			
			// toma los elementos encontrados
			TblAsset asset = MasterCardDAO.findAssetById( cveAsset ) ;
			
			setCveAsset( asset.getCveAsset( ) ) ;
//			f.getPackageManager( ).setCveAsset( asset.getCveAsset( ) ) ;
			
			// actualiza los paquetes
			MCUtil.updatePackageManager( MasterCardDAO.getAllPackagesOfAsset( asset.getCveAsset( ) , 1 ) , packageManager ) ;
			
			request.setAttribute( "ItemFinded" , asset ) ;
			request.setAttribute( "IdSearched" , new Integer( cveAsset ) ) ;
			
			// coloca el form en el request
			request.setAttribute( "AssetModificarPaquetesForm" , this ) ;
                        MasterCardDAO.closeEntityManager( ) ;
		}
		
                MasterCardDAO.closeEntityManager( ) ;
		return errors ;
	}
}
